﻿using ManagementApi.Models.Auth;
using Modules;
using Modules.Constructor;
using Modules.Corp;
using Modules.Project;
using Modules.System.User;
using PmSoft.Entity;

namespace ManagementApi.Models.User
{
    /// <summary>
    /// 登录用户信息
    /// </summary>
    public class LoginUserInfoDto
    {
        /// <summary>
        /// 登录对象ID
        /// </summary>
        public int ObjectId { get; set; }
        /// <summary>
        /// 登录对象类型
        /// </summary>
        public UserType Type { get; set; }
        /// <summary>
        /// 登录对象名称
        /// </summary>
        public string Name { get; set; } = string.Empty;
        /// <summary>
        /// 用户角色编码集合
        /// </summary>
        public IEnumerable<string> Roles { get; set; } = new List<string>();
        /// <summary>
        /// 用户权限标识集合
        /// </summary>
        public IEnumerable<string> Perms { get; set; } = new List<string>();

        /// <summary>
        /// 项目详情
        /// </summary>
        public ProjectInfo? Project { get; set; }

        public static LoginUserInfoDto Builder(SysUser sysUser, IEnumerable<string> roles, IEnumerable<string> perms)
        {
            return new LoginUserInfoDto { Name = sysUser.Name, ObjectId = sysUser.UserId, Type = UserType.SysUser, Roles = roles, Perms = perms };
        }

        public static LoginUserInfoDto Builder(CorpInfo corpInfo)
        {
            return new LoginUserInfoDto { Name = corpInfo.Name, ObjectId = corpInfo.CorpId, Type = UserType.Corp, Roles = new string[] { UserType.Corp.ToString() } };
        }

        public static LoginUserInfoDto Builder(ConstructorInfo constructor)
        {
            return new LoginUserInfoDto { Name = constructor.Name, ObjectId = constructor.ConstructorId, Type = UserType.Constructor, Roles = new string[] { UserType.Constructor.ToString() } };
        }

        public static LoginUserInfoDto Builder(ManagerInfo manager)
        {
            return new LoginUserInfoDto { Name = manager.Name, ObjectId = manager.ManagerId, Type = UserType.Manager, Roles = new string[] { UserType.Manager.ToString() } };
        }

        public static LoginUserInfoDto Builder(CommanderInfo commander)
        {
            return new LoginUserInfoDto { Name = commander.Name, ObjectId = commander.CommanderId, Type = UserType.Commander, Roles = new string[] { UserType.Commander.ToString() } };
        }
    }
}
